from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
def test_TJsuccess():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.switch_to.frame("iframe-1")
    sleep(2)
    driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/a").click()
    sleep(2)
    driver.find_element(By.XPATH, "/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/div[2]/input").send_keys("110")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.quit()

def test_TJfail1():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.switch_to.frame("iframe-1")
    sleep(2)
    driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/a").click()
    sleep(2)
    driver.find_element(By.XPATH, "/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/div[2]/input").send_keys("")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    text = driver.find_element(By.XPATH, "/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/span").text
    assert text == "联系人不能为空。", "输入空的联系人,进行保存,用例执行失败"
    driver.quit()

def test_TJfail2():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.switch_to.frame("iframe-1")
    sleep(2)
    driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/a").click()
    sleep(2)
    driver.find_element(By.XPATH, "/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/div[2]/input").send_keys("2222222222222222222222222222222")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    text = driver.find_element(By.XPATH, "/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/span").text
    assert text == "联系人长度应当不超过30，且不小于0。", "输入长度31位的联系人,进行保存,用例执行失败"
    driver.quit()

def test_TJsuccess1():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.switch_to.frame("iframe-1")
    sleep(2)
    driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/a").click()
    sleep(2)
    driver.find_element(By.XPATH, "/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/div[2]/input").send_keys("6666666666")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.find_element(By.XPATH,'/html/body/div/div[1]/div[2]/form/table/tbody/tr[1]/td[1]/div/input').send_keys("878979465465513")
    sleep(2)
    driver.quit()

def test_TJfail3():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.switch_to.frame("iframe-1")
    sleep(2)
    driver.find_element(By.XPATH, "/html/body/div[2]/div[1]/a").click()
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div/div[1]/div[2]/form/table/tbody/tr[1]/td[1]/div/input').send_keys(
            "132111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    text = driver.find_element(By.XPATH, "/html/body/div/div[1]/div[2]/form/table/tbody/tr[1]/td[1]/span").text
    assert text == "名称长度应当不超过100，且不小于0。", "输入长度101位的联系人,进行保存,用例执行失败"
    sleep(2)
    driver.quit()
def test_TJsuccess3():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/ul[1]/li[8]/button').click()
    sleep(2)
    driver.switch_to.frame("iframe-superadmin")
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[1]/div/a/h3').click()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("77585212")
    sleep(2)
    driver.find_element(By.ID, "realname").send_keys("111")
    sleep(2)
    driver.find_element(By.ID, "genderm").click()
    sleep(2)
    ele = driver.find_element(By.ID, "role")
    sle_obj = Select(ele)
    sle_obj.select_by_value("support")
    sleep(2)
    driver.find_element(By.ID, "password1").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "password2").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "email").send_keys("155@qq.com")
    sleep(2)
    driver.find_element(By.ID,"submit").click()
    driver.quit()
def test_TJfail4():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/ul[1]/li[8]/button').click()
    sleep(2)
    driver.switch_to.frame("iframe-superadmin")
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[1]/div/a/h3').click()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("")
    sleep(2)
    driver.find_element(By.ID, "realname").send_keys("111")
    sleep(2)
    driver.find_element(By.ID, "genderm").click()
    sleep(2)
    ele = driver.find_element(By.ID, "role")
    sle_obj = Select(ele)
    sle_obj.select_by_value("support")
    sleep(2)
    driver.find_element(By.ID, "password1").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "password2").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "email").send_keys("1555555@qq.com")
    sleep(2)
    driver.find_element(By.ID,"submit").click()
    sleep(2)
    text = driver.find_element(By.XPATH, "/html/body/div/div/div[2]/div/div[2]/form/table/tbody/tr[1]/td/span").text
    assert text == "用户名不能为空。;用户名应当为字母或数字的组合，至少三位", "输入空的用户名,进行保存,用例执行失败"
    driver.quit()
def test_TJfail5():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/ul[1]/li[8]/button').click()
    sleep(2)
    driver.switch_to.frame("iframe-superadmin")
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[1]/div/a/h3').click()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("l")
    sleep(2)
    driver.find_element(By.ID, "realname").send_keys("111")
    sleep(2)
    driver.find_element(By.ID, "genderm").click()
    sleep(2)
    ele = driver.find_element(By.ID, "role")
    sle_obj = Select(ele)
    sle_obj.select_by_value("support")
    sleep(2)
    driver.find_element(By.ID, "password1").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "password2").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "email").send_keys("1555555@qq.com")
    sleep(2)
    driver.find_element(By.ID,"submit").click()
    sleep(2)
    text = driver.find_element(By.XPATH, "/html/body/div/div/div[2]/div/div[2]/form/table/tbody/tr[1]/td/span").text
    assert text == "用户名应当为字母或数字的组合，至少三位", "输入一位的用户名,进行保存,用例执行失败"
    driver.quit()
def test_TJfail6():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/ul[1]/li[8]/button').click()
    sleep(2)
    driver.switch_to.frame("iframe-superadmin")
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[1]/div/a/h3').click()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("ll")
    sleep(2)
    driver.find_element(By.ID, "realname").send_keys("111")
    sleep(2)
    driver.find_element(By.ID, "genderm").click()
    sleep(2)
    ele = driver.find_element(By.ID, "role")
    sle_obj = Select(ele)
    sle_obj.select_by_value("support")
    sleep(2)
    driver.find_element(By.ID, "password1").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "password2").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "email").send_keys("1555555@qq.com")
    sleep(2)
    driver.find_element(By.ID,"submit").click()
    sleep(2)
    text = driver.find_element(By.XPATH, "/html/body/div/div/div[2]/div/div[2]/form/table/tbody/tr[1]/td/span").text
    assert text == "用户名应当为字母或数字的组合，至少三位", "输入两位的用户名,进行保存,用例执行失败"
    driver.quit()
def test_TJfail7():
    driver = webdriver.Chrome()
    driver.get("http://localhost/ranzhi/www/crm/customer-browse.html")
    sleep(2)
    driver.maximize_window()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("123456")
    sleep(2)
    driver.find_element(By.NAME, "password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "submit").click()
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/ul[1]/li[8]/button').click()
    sleep(2)
    driver.switch_to.frame("iframe-superadmin")
    sleep(2)
    driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[1]/div/a/h3').click()
    sleep(2)
    driver.find_element(By.ID, "account").send_keys("lllllllll")
    sleep(2)
    driver.find_element(By.ID, "realname").send_keys("")
    sleep(2)
    driver.find_element(By.ID, "genderm").click()
    sleep(2)
    ele = driver.find_element(By.ID, "role")
    sle_obj = Select(ele)
    sle_obj.select_by_value("support")
    sleep(2)
    driver.find_element(By.ID, "password1").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "password2").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID, "email").send_keys("1555555@qq.com")
    sleep(2)
    driver.find_element(By.ID,"submit").click()
    sleep(2)
    text = driver.find_element(By.XPATH, "/html/body/div/div/div[2]/div/div[2]/form/table/tbody/tr[2]/td/span").text
    assert text == "真实姓名不能为空。", "输入空的姓名,进行保存,用例执行失败"
    driver.quit()
if __name__ == '__main__':
     #TJsuccess()
    test_TJfail1()
    test_TJfail2()
     #test_TJsuccess2()
    test_TJfail3()
     #test_TJsuccess3()
    test_TJfail4()
    test_TJfail5()
    test_TJfail6()
    test_TJfail7()